package com.nyist.myticket.web;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nyist.myticket.biz.entity.FileRel;
import com.nyist.myticket.biz.entity.User;
import com.nyist.myticket.biz.service.FileRelService;
import com.nyist.myticket.core.common.R;
import com.nyist.myticket.core.utils.DateUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * *
 *
 * @author yangxiaogen
 * @date 2021/12/23 15:18
 */
@RestController
//@RequestMapping("/test")
@Api(tags = "测试使用")
@Slf4j
public class FileRelController {

    @Autowired
    private FileRelService fileRelService;

    @GetMapping("/file")
    public R getFileInfo(){

        ArrayList<String> queryList = new ArrayList<>();
        queryList.add("9922050709500026880815");
        queryList.add("9922042816080002080761");
        queryList.add("9922042811510000720525");
        queryList.add("9922042809280000780519");
        queryList.add("9922042717580000120699");
        QueryWrapper<FileRel> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("relation_id", queryList);
        List<FileRel> list = fileRelService.list(queryWrapper);

        Map<String, List<FileRel>> collect = list.stream().collect(Collectors.groupingBy(FileRel::getRelationId));

        User user = new User();

        for (Map.Entry<String, List<FileRel>> stringListEntry : collect.entrySet()) {
            if ("9922042717580000120699".equals(stringListEntry.getKey())) {
                user.setFileRels(stringListEntry.getValue());
            }
            log.info("key:{}, value:{}", JSONObject.toJSONString(stringListEntry.getKey()), JSONObject.toJSONString(stringListEntry.getValue()));
        }

        log.info("查询用户信息被调用了...数据大小为...{}", list.size());
        return R.ok().put("200","成功!")
                .put("time", DateUtils.getLocalTime())
                .put("date",user);
    }

}
